package com.wang.test;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.wang.ioc.IocManager;
import com.wang.ioc.annotation.ViewComponent;
import com.wang.ioc.annotation.ViewComponent.VisibilityState;

public class ListAdapter extends BaseAdapter {
	private Context context;
	private String[] data;
	
	public ListAdapter(Context context,String[] data) {
		super();
		this.context=context;
		this.data=data;
	}

	@Override
	public int getCount() {
		return data.length;
	}

	@Override
	public Object getItem(int position) {
		return data[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View v=LayoutInflater.from(context).inflate(R.layout.item, null);
		final Item item=new Item();
		OnClickListener listener=new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(v==item.LinearLayout3){
					Toast.makeText(context, "选中了"+data[position], Toast.LENGTH_SHORT).show();
				}
				
			}
		};
		IocManager.getInstance(context).autowireView(context, item, v, listener);
		item.textView1.setText(data[position]+position);
		return v;
	}
	class Item{
		TextView textView1;
		@ViewComponent(imageResource=R.drawable.ic_launcher,defaultVisibility=VisibilityState.GONE)
		ImageView imageView1;
		@ViewComponent(clickEventSource=true,backgroundColor=0xff8822cc)
		LinearLayout LinearLayout3;
	}
}
